<?php
@session_start();
if (!isset($_SESSION['id_user']))
	//header('Location://localhost/firstclassapartmentscordoba/panel_control/login.php');
	//header('Location:http://firstclassapartment.com.ar/panel_control/login.php');

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="es">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta name="description" content="Atenticaci&oacute;n | Panel de Control | First Class Apartments Cordoba Argentina">
		<meta name="author" content="Pulce Web Solutions - www.pulce.com.ar">
		<!--Para que las páginas se muestren correctamente y el zoom funcione bien en los dispositivos móviles-->
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta name="keywords" content="Departamento,Alquiler,Temporal,Cordoba,Capital,Argentina,First Class Apartments,Alojamiento,Turismo,Panel,Control,LogIn,Auenticaci&oacute;n">

		<title>Cotizaci&oacute;n y Moneda | Panel de Control | First Class Apartments C&oacute;rdoba Argentina</title>

		<?php
			include_once('../links.php');
			include_once('menu_bar.php');
		?>
		<link href="../css/tooltipster.css" rel="stylesheet">
		<link href="../css/jquery.dataTables.css" rel="stylesheet">
		<link href="../css/dataTables.responsive.css" rel="stylesheet">

		<!--JQUERY-->
		<script src="http://code.jquery.com/jquery-2.1.0.js"></script>
		<!--BOOTSTRAP-->
		<script src="../js/bootstrap.min.js"></script>
		<!--CUSTOM JS-->
		<script src="../js/functions.js"></script>
		<!-- TOOLTIP -->
		<script src="../js/jquery.tooltipster.min.js"></script>
		<link href="../css/tooltipster.css" rel="stylesheet">
		<!-- DATATABLES -->
		<script src="../js/jquery.dataTables.js"></script>
		<!-- DATATABLES RESPONSIVE 
		<script src="../js/dataTables.responsive.js"></script>-->
		<!-- DATATABLES PLUGIN - DATE UK -->
		<script src="../js/date-uk.js"></script>
		<!-- DATATABLES PLUGIN - RELOAD AJAX -->
		<script src="../js/fnReloadAjax.js"></script>
		
		
		<script type="text/javascript">

		$(document).ready(function(){

			$('#tabla').dataTable({
				"language": {"url": "../css/es_ES.txt"},
	    		"ajax": {
		            "url": "ajax_tabla_cotizacion.php",
		            "dataSrc": "",
		            "data": function ( d ) {
       					 d.action = 'getCotizacionHr';
       				}
		        },
	        	"columns": [
					{ "data": "Fecha" },
	        		{ "data": "Moneda" },		            
		            { "data": "Descripcion" },
		            { "data": "Cotizacion" }	            
		        ],
		        "columnDefs": [
		        	{ 	"type": "date-uk", 
		        		"targets": 0
		        }],
		        "order": [[ 0, "desc" ]]
			});

			var oTablaMoneda=$('#tabla-moneda').dataTable({
				"language": {"url": "../css/es_ES.txt"},
	    		"ajax": {
		            "url": "ajax_tabla_cotizacion.php",
		            "dataSrc": "",
		            "data": function ( d ) {
       					 d.action = 'getMonedas';
       				},
		        },
	        	"columns": [
	        		{ "data": "Simbolo" },		            
		            { "data": "Descripcion" },
		            { "data": "ISO" }
		        ]
			});

			function reload_moneda(){
				var table = $('#tabla-moneda').dataTable();
				table.fnReloadAjax();
			}

			$('#tabla-moneda tbody').on( 'click', 'tr', function () {
		        var trid = $(this).closest('tr').attr('id');
		        g("ajax_tabla_cotizacion.php?"+a("getMoneda")+c('id',trid),'result-modal','div-msg3','div-img2',false);
		        $('#btn-modificar').show();
				$('#btn-eliminar').show();
				$('#btn-guardar').hide();
				$('#lblMoneda').text('Editar Moneda');
		        hideMsgModal();
		        $('#modalMoneda').modal('show');
		    } );

			$('.tooltip').tooltipster({
                contentAsHTML: true,
                interactive:true,
                animation: 'grow'
        	});

    		$('#btn-menu').on('click',function(e){
				$(location).attr('href','./index.php');
			});

			$('#btn-act-cotizacion').on('click',function(e){
				g("ajax_tabla_cotizacion.php?"+a("actCotizacion"),'','div-msg1','div-img',true);
			});

			$('#btn-nueva').on('click',function(e){
				$('#btn-modificar').hide();
				$('#btn-eliminar').hide();
				$('#btn-guardar').show();
				$('#lblMoneda').text('Nueva Moneda');
				limpiarDatos();
				hideMsgModal();
				$('#modalMoneda').modal('show');
			});

			$('#btn-modificar').on('click',function(e){
				g("ajax_tabla_cotizacion.php?"+a("updMoneda")+v('simbolo')+v('descripcion')+v('iso')+v('id_modal'),'','msg-modal','img-modal',true);
				reload_moneda();
			});

			$('#btn-eliminar').on('click',function(e){
				$('#modalConfirmacion').modal('show');
			});

			$('#btn-guardar').on('click',function(e){
				g("ajax_tabla_cotizacion.php?"+a("newMoneda")+v('simbolo')+v('descripcion')+v('iso'),'','msg-modal','img-modal',true);
				reload_moneda();
			});

			$('#btn-confirm-yes').on('click',function(e){
				g("ajax_tabla_cotizacion.php?"+a("delMoneda")+v('id_modal'),'','msg-modal','img-modal',true);
				reload_moneda();
				$('#modalConfirmacion').modal('hide');
			});

			$('#btn-salir').on('click',function(e){
				hideMsgModal();
			});
			
			function hideMsgModal(){
				if (isSet('msg-modal'))
					$('#msg-modal').fadeOut();
			}
			$('#modalMoneda').on('change',function(e){
				hideMsgModal();
			});

			function limpiarDatos(){
				$('#simbolo').val('');
				$('#iso').val('');
				$('#descripcion').val('');
			}

		});
 	</script>

	</head>
	<body class="panel">
		<div class="container">
			<div class="row box-central">
				<div class="row">
					<div class="col-xs-6">
						<div class="row">
							<div class="col-xs-5">
								<h1>Cotizaci&oacute;n</h1>
							</div>
							<div class="col-xs-2">
								<div id ="div-img">
								</div>
							</div>
							<div class="col-xs-5">
								<button id="btn-act-cotizacion" class="btn btn-md btn-success">Actualizar Cotizaci&oacute;n</button>
							</div>
						</div>
						<div class="row">
							<div class="col-xs-12">
								<?php
								$result= getDateRate(0);
								echo html_entity_decode($result);
								?>
							</div>
						</div>
						<div id="div-msg1" class="margin-top-1em" style="display:none"></div>
						<div class="row">
							<div class="col-xs-5">
								<h2>Cotizaci&oacute;n Hist&oacute;rica</h2>
							</div>
						</div>
						<div class="row back-table">
							<table id="tabla" class="display responsive nowrap">
								<thead>
						            <tr>
						            	<th>Fecha</th>
						                <th>Moneda</th>
						                <th>Descripci&oacute;n</th>
						                <th>Cotizaci&oacute;n Respecto al U$S</th>
						            </tr>
						        </thead>
							</table>
						</div>
						<div id="div-msg2" class="margin-top-1em" style="display:none">
						</div>
					</div>
					<div class="col-xs-1">
						<img src='../img/separador2.png'/>
					</div>
					<div class="col-xs-5">
						<div class="row">
							<div class="col-xs-5">
								<h1>Moneda</h1>
							</div>
							<div class="col-xs-2">
								<div id ="div-img2">
								</div>
							</div>
							<div class="col-xs-4">
								<button id="btn-nueva" type="button" class="btn btn-md btn-info" data-dismiss="modal">Nueva Moneda</button>
							</div>
						</div>
						<div class="row back-table margin-top-1em">
							<table id="tabla-moneda" class="display responsive nowrap">
								<thead>
						            <tr>
						            	<th>S&iacute;mbolo</th>
						                <th>Descripci&oacute;n</th>
						                <th>ISO</th>
						            </tr>
						        </thead>
							</table>
						</div>
						<div id="div-msg3" class="margin-top-1em" style="display:none">
						</div>
					</div>
				</div>
				<div class="row margin-top-1em">
					<div class="col-xs-4 col-xs-offset-4">
						<button id="btn-menu" class="btn btn-lg btn-danger" style="width:90%">Volver al Men&uacute; Principal</button>
					</div>
				</div>
			</div>
			<div id="div-result">
			</div>
			<div class="row margin-top-1em">
					

			</div>

			<!-- Modal: Moneda -->
			<div id="modalMoneda" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
				<div class="modal-dialog modal-sm modal-dialog-alert">
			    	<div class="modal-content modal-content-alert">
			      		<div class="modal-header modal-header-alert">
			      			<div class="row">
			      				<div class="col-xs-5">
			        				<h2 class="modal-title" id="lblMoneda"></h2>
			        			</div>
			        			<div class="col-xs-2">
			        				<div id="img-modal"></div>
			        			</div>
			        		</div>
			       		</div>
			      		<div class="modal-body modal-body-alert">
			      			<div class="row margin-top-1em">
			      				<label class="col-xs-2 col-xs-offset-2 control-label label-custom">S&iacute;mbolo:</label>
								<div class="col-xs-8">
									<input type="text" id="simbolo"/>
								</div>
			      			</div>
			      			<div class="row">
			      				<label class="col-xs-2 col-xs-offset-2 control-label label-custom">Descripci&oacute;n:</label>
								<div class="col-xs-8">
									<input type="text" id="descripcion"/>
								</div>
			      			</div>
			      			
			      			<div class="row">
			      				<label class="col-xs-2 col-xs-offset-2 control-label label-custom">C&oacute;digo ISO:</label>
								<div class="col-xs-8">
									<input type="text" style="" id="iso"/>
									<img src="../img/symbol/help.png" style="cursor:pointer;display: inline;" title="Seg&uacute;n Estandar Internacional ISO 4217 (Códigos internacionales de Monedas)</br> <a target='_blank' href='http://es.wikipedia.org/wiki/ISO_4217'>Ver C&oacute;digos</a>" class="tooltip"/>
								</div>
			      			</div>
			      			<input type="hidden" id="id_modal"/>
						</div>
						<div class="modal-footer modal-footer-alert">
							<button id="btn-guardar" type="button" class="btn btn-success btn-custom">Guardar</button>
					    	<button id="btn-modificar" type="button" class="btn btn-success btn-custom">Modificar</button>
					    	<button id="btn-eliminar" type="button" class="btn btn-danger btn-custom">Eliminar</button>
					        <button id="btn-salir" type="button" class="btn btn-info btn-custom" data-dismiss="modal">Salir</button>
					    </div>
					    <div id="msg-modal">
						</div>
					    <div id="result-modal">
						</div>
			      	</div>
			    </div>
			</div>
			<!-- Modal: Confimacion -->
			<div id="modalConfirmacion" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
				<div class="modal-dialog modal-sm modal-dialog-alert">
			    	<div class="modal-content modal-content-alert">
			      		<div class="modal-header modal-header-alert">
			        		<h2 class="modal-title" id="lblSrv">Confirmar Eliminar Moneda</h2>
			       		</div>
			      		<div class="modal-body modal-body-alert">
			      			<p>¿Est&aacute; seguro que desea eliminar la Moneda?.</br>Se eliminar&aacute;n adem&aacute;s los valores de cotizaci&oacute;n y su actualizaci&oacute;n diaria</p>
						</div>
						<div class="modal-footer modal-footer-alert">
					    	<button id="btn-confirm-yes" type="button" class="btn btn-danger btn-custom">Si</button>
					        <button type="button" class="btn btn-info btn-custom" data-dismiss="modal">No</button>
					    </div>
			      	</div>
			    </div>
			</div>
		</div>
	</body>
</html>